import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// import loginPage from '../views/login.vue'
// import indexPage from '../views/index.vue'

const routes = [
    { path: '/',redirect:'/index'},
    { 
    path: '/index',
    component:() => import('../views/index'),
    redirect:'/index/banners',
    meta:{title:'首页'},
    children:[
      { path: 'banners',
      meta:{title:'轮播图管理'}, 
      component:() => import('../views/shouye/banner'),
      beforeEnter: (to, from,next) => {
        console.log('独享守卫')
        // reject the navigation
        next()
      },
    },
      { path: 'category',meta:{title:'分页管理'},component:() => import('../views/shouye/category')},
      { path: 'recomend',meta:{title:'为你推荐管理'}, component:() => import('../views/shouye/recomend')},
      { path: 'fl',meta:{title:'商品分类管理'},component:() => import('../views/shangpin/fl')},
      { path: 'pinpai',meta:{title:'商品品牌管理'},component:() => import('../views/shangpin/pinpai')},
      { path: 'danpin',meta:{title:'商品单品管理'},component:() => import('../views/shangpin/danpin')},
      { path: 'shangpin',meta:{title:'商品管理'},component:() => import('../views/shangpin/shangpin')},
      { path: 'news',meta:{title:'新闻管理'},component:() => import('../views/xinwen/news')},
    ]
  },
    { path: '/login', component:() => import('../views/login')},
  ]


  const router = new VueRouter({
    routes, // `routes: routes` 的缩写
  })

  router.beforeEach((to, from, next) => {
    // 如果用户未能验证身份，则 `next` 会被调用两次
    next()
  })

  export default router